package cn.ming.wfchat.app.moment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import cn.ming.wfchat.R;
import cn.ming.wfchat.app.utils.ImageLoaderUtil;

/**
 * 图片显示Adapter
 * Created by kuyue on 2017/6/19 下午3:59.
 * 邮箱:595327086@qq.com
 */

public class PostArticleImgAdapter extends RecyclerView.Adapter<PostArticleImgAdapter.MyViewHolder> {

    private List<String> mDatas;
    private final LayoutInflater mLayoutInflater;
    private final Context mContext;
    private boolean isVideo;


    public PostArticleImgAdapter(Context context, List<String> datas) {
        this.mDatas = datas;
        this.mContext = context;
        this.mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(mLayoutInflater.inflate(R.layout.item_post_activity, parent, false));
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        if (position < mDatas.size()) {
            ImageLoaderUtil.displaylocal(holder.imageView, mDatas.get(position));
        } else {
            holder.imageView.setImageResource(R.mipmap.icon_imgadd);
        }

    }

    public void setmDatas(List<String> mDatas, boolean isVideo) {
        this.mDatas = mDatas;
        this.isVideo = isVideo;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        if (isVideo) {
            return 1;
        }
        return mDatas.size() < 9 ? mDatas.size() + 1 : 9;

    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        ImageView imageView;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.sdv);
        }
    }

    public List<String> getImageUrls() {
        return mDatas;
    }


}
